package com.xinghuo.building.ui.component.mine

import android.os.Bundle
import android.view.View
import android.widget.Toast
import androidx.activity.viewModels
import com.xinghuo.building.R
import com.xinghuo.building.data.database.AppDataBase
import com.xinghuo.building.data.database.Student
import com.xinghuo.building.data.database.StudentDao
import com.xinghuo.building.databinding.MineActivityBinding
import com.xinghuo.building.ui.base.BaseActivity
import com.xinghuo.building.ui.base.BaseViewModel
import dagger.hilt.android.AndroidEntryPoint

/**
 * desc   : 模版
 * author : chendaning
 * date   : 7/4/21
 */
@AndroidEntryPoint
class MineActivity : BaseActivity<MineActivityBinding>() {
    private val viewModel: MineViewModel by viewModels()

    override fun getViewModel(): BaseViewModel? {
        return viewModel
    }

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)

        mBindView.model = viewModel
        mBindView.lintener = this.listener


        mBindView.bean = viewModel.mUserBean
    }

    override fun getLayoutId(): Int {
        return R.layout.mine_activity
    }

    override fun observeViewModel() {
        Toast.makeText(this, viewModel.getName(), Toast.LENGTH_LONG).show()
    }


    var student: Student? = null
    private val listener: View.OnClickListener = View.OnClickListener {
//        println("-------------")
//        viewModel.loadData()

        val sDao: StudentDao = AppDataBase.instance.getStudentDao()
        student = sDao.getAllStudents()[0]
        println("=========size=")
        mBindView.student = student
    }
}